<h1 class="show_title">Library</h1>

<% form_tag :search, :id => "search_forma", :url => {:action => "index"} do %>
  <%= text_field :search, :text, :size => 50  %>
  <%= submit_tag 'Search', :class => "default_button_class" %>
<% end %>
<% if @searchON == false then %>
	<p style="text-align: center;">CATEGORIES</p>
	<table class="library_categories_table">
		<tr>
			<% for category in @categories -%>	
				<td id="<%= category.name %>">
					<div class="entry">
						<% if category.id == params[:cat].to_i then %>
							<%= link_to category.name, {:controller => 'codes', :action => 'index', :cat => category.id, :lang => params[:lang], :page => 1}, :post => true, :class => "categories_table_a selected" %>
						<% else %>
							<%= link_to category.name, {:controller => 'codes', :action => 'index', :cat => category.id, :lang => params[:lang], :page => 1}, :post => true, :class => "categories_table_a" %>
						<% end %>
					</div>
				</td>
			<% end %>
		</tr>
	</table>

	<p style="text-align: center;">LANGUAGES</p>
	<table class="library_categories_table">
		<tr>
			<% for language in @languages -%>
				<td>
					<div class="entry">
						<% if language.id == params[:lang].to_i then %>
							<%= link_to language.language_name, {:controller => 'codes', :action => 'index', :lang => language.id, :cat => params[:cat], :page => 1}, :post => true, :class => "categories_table_a selected" %>
						<% else %>
							<%= link_to language.language_name, {:controller => 'codes', :action => 'index', :lang => language.id, :cat => params[:cat], :page => 1}, :post => true, :class => "categories_table_a" %>
						<% end %> 
					</div>
				</td>
			<% end %>
		</tr>
	</table>
	<% end%>
<br />

<table style="width: 100%">
	<tr>
		<td>
			<table style="width: 100%">
				<tr class="legend_tr">
					<td style="width: 70%"><a class="legend_a">Title</a>/<a class="legend_a">Author</a></td>
					<td class="legend_td" style="width: 10%"><a class="legend_a">Views</a></td>
					<td class="legend_td" style="width: 10%"><a class="legend_a">Comments</a></td>
					<td class="legend_td" style="width: 10%"><a class="legend_a">Ratio</a></td>		
				</tr>
			</table>
			
			<% if @codes.count() > 0 then %>
				<% @codes.each do |code| %>
				<table class="codes_table">
	  				<tr>
						<td style="width: 70%">
							<%= link_to code.title, code %> 
							by 
							<%= link_to code.getAuthorName, user_path(code.getAuthorName) %>
							<br />
							<p><%=h code.shortdescription %></p>
							<p class="codes_table_p">
								<%= link_to code.getProgLangName, code.getProgLang, :class => "codes_table_a" %>
								/
								<%= link_to code.getCategoryName, code.getCategory, :class => "codes_table_a" %>
							</p>
						</td>
						<td class="codes_table_td" style="width: 10%;"> <%= code.views %> </td>
	  					<td class="codes_table_td" style="width: 10%;"> <%= code.getNumComments %></td>
	   				 	<td class="codes_table_td" style="width: 10%;"> <%= code.getSumGrades %>    </td>	
	  				</tr>
				</table>
				<% end %>
			<% else %>
				<h3 style="text-align: center">Unfortunately your search didn't return any results.</h3>
			<% end %>
		</td>
	</tr>
</table>
<br />

<% if @codes.count() > 0 then %>
	Page: 
	<% i = 1; while i <= @numPages %>
		<% if i == params[:page].to_i %>
			<span class ="default_button_class default_button_class_selected" ><%= i %></span>
		<% else %>
	   		<%= link_to i, {:controller => 'codes', :action => 'index', :page => i, :lang => params[:lang], :cat => params[:cat]}, :post => true, :class => "default_button_class" %>
		<% end %>
		<%  i += 1 %>
	<% end %>
<% end %>

<!-- #SMART LISTING ... za več kot 20 strani#
IF listingNum <= 5
  izpiši vse štiri
ELSE IF listingNum > 5
  IF listingNum == fist
    izpiši prvega in dva za njim
  ELSE IF listingNum == last
    ispiši zadnjega in dva pred njim
  ELSE
    izpiši prvega, potem tri pike, potem enega pred trenutno aktivnim, trenutno aktivnega in enega za trenutno aktvino, tri pike, in zadnjega
-->

